﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Teamcenter.Soa.Client.Model;

namespace TC4T_WinForm
{
    public partial class UidForm : TCForm
    {
        public UidForm()
        {
            InitializeComponent();
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox1.Text != "")
                {
                    string uid = textBox1.Text;
                    ModelObject mo = TCHelper.LoadObjects(new string[] { uid }).GetPlainObject(0);
                    try
                    {
                        Dictionary<string, Dictionary<string, Property>> dic;

                        if (mo is Teamcenter.Soa.Client.Model.Strong.GroupMember)
                        {
                            dic = TCHelper.GetPropertiesByUids(new string[] { uid }, new string[] { "user_name" });
                            Property p_username = dic[uid]["user_name"];
                            string user_name = p_username.DisplayableValue;
                            richTextBox1.Text = "user_name:" + user_name + "\n";
                        }
                        //else if (mo is Teamcenter.Soa.Client.Model.Strong.EPMTaskTemplate)
                        //{
                        //    dic = TCHelper.GetPropertiesByUids(new string[] { uid }, new string[] { "user_name" });
                        //    Property p_username = dic[uid]["user_name"];
                        //    string user_name = p_username.DisplayableValue;
                        //    richTextBox1.Text = "user_name:" + user_name + "\n";
                        //}
                        else
                        {
                            dic = TCHelper.GetPropertiesByUids(new string[] { uid }, new string[] { "object_type", "object_name" });
                            Property p_type = dic[uid]["object_type"];
                            Property p_name = dic[uid]["object_name"];

                            string typename = p_type.DisplayableValue;
                            string name = p_name.DisplayableValue;
                            richTextBox1.Text = "type:" + typename + "\n";
                            richTextBox1.Text += "name:" + name;
                        }

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
    }
}
